package com.jalarbee.web.jsf.controller;

import java.util.ArrayList;
import java.util.List;

import com.jalarbee.stock.product.business.Product;
import com.jalarbee.stock.product.service.ProductService;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@RequestScoped
public class ProductsController {

    @Inject private ProductService productService;// = (ProductService) FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean("productService");
    private int currentRow;
    private List<Product> list = new ArrayList<Product>();
    private Set<Integer> keys = new LinkedHashSet<Integer>();

    public ProductsController() {
    }

    public List<Product> getProducts() {
        if (list.isEmpty()) {
            list = productService.findAll(null);
        }
        return list;
    }

    public Set<Integer> getKeys() {
        for (int i = 0; i < list.size(); i++) {
            keys.add(i);
        }
        return keys;
    }

    public int getCurrentRow() {
        return currentRow;
    }

    public void setCurrentRow(int currentRow) {
        this.currentRow = currentRow;
    }

    public void setProductService(ProductService productService) {
        this.productService = productService;
    }
}
